<?php


namespace App\Services\Result;

use App\Interf\Resultable;
use Monolog\Logger;
use ParamConfig;

use App\Services\Result\BaseResult;

use App\Models\LogHelper;

class ChineseMedicineConstitutionTestingHlsResult extends BaseResult implements Resultable
{
    private $answers;

    private $totalSummaryAttrObj;


    public function __construct($answersStr = null)
    {
        $this->answers = $this->convertAnswer($answersStr);
        $this->totalSummaryAttrObj = $this->configAttrObj(1,'体质特征');

    }

    public function result()
    {
        $attrs = [];
        array_push($attrs,$this->totalSummaryAttr());
        $data['attrs'] = $attrs;
        $data['chatparam'] = $this->getChatparam();
        //图类型为雷达图
        $data['chatType'] = '';
        return $data;

    }


    protected function totalSummaryAttr(){
        $note =$this->getNote();
        $obj = $this->totalSummaryAttrObj;
        $obj = $this->compactAttrObj($obj['attr_id'],$obj['title'],$note);
        LogHelper::log($obj);
        return $obj;
    }



      public function  getNote()
      {

          $values=ParamConfig::getByTag('tag.42.chinese.medicine.constitution.testing.hls');
          foreach ($values as $v)
          {

              $temp=$v['key'];

              for($k=0;$k<4;$k++)
              {
                  if((stripos($v['key'], '@')!==false))
                  {
                      $i=stripos($v['key'], '@');
                      $searchStr=substr($v['key'],$i,3);
                      $index=substr($v['key'],$i+1,2);
                      $singelAns=$this->getAnswerObjByIndex($this->answers,$index);
                      $replaceStr=round($singelAns['weight']);
                  }
                  $v['key']=str_replace($searchStr, $replaceStr,$v['key']);

              }
              $str=$v['key'];
              if($this->removeSameAns())
              {
                  return ParamConfig::getValue('default_answer');
              }
              if(eval("return $str;"))
              {
                  return ParamConfig::getValue($temp);
              }
          }
          return ParamConfig::getValue('default_answer');
      }


      public function removeSameAns()
      {
               $tempArr=[];
              $arrSameCodes=[35,36,37,38];
              foreach ($arrSameCodes as $arrSameCode){
                  $singelAns=$this->getAnswerObjByIndex($this->answers,$arrSameCode);
                  $targetScore=round($singelAns['weight']);
                  array_push($tempArr,$targetScore);
              }
              if((50==$tempArr[0] && $tempArr[0]==$tempArr[1] && $tempArr[1]==$tempArr[2] && $tempArr[2]==$tempArr[3]) || (75==$tempArr[0] && $tempArr[0]==$tempArr[1] && $tempArr[1]==$tempArr[2] && $tempArr[2]==$tempArr[3]) || (100==$tempArr[0] && $tempArr[0]==$tempArr[1] && $tempArr[1]==$tempArr[2] && $tempArr[2]==$tempArr[3]) ){
                          return true;
              }
              return false;

      }


    protected function getChatparam(){
        $chatdata = [];
        return $chatdata;
    }






}